<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var obj = {
            id: 1,
            pname: '小米',
            price: 9999
        }
        // Object.defineProperty方法用于定义新属性或改变原有属性
        //1.value用来增添或修改原有的属性
        Object.defineProperty(obj, 'pname', {
            value: '华为'
        });
        Object.defineProperty(obj, 'num', {
            value: 1000,
            enumerable: true//新添属性默认为false不会被遍历   枚举
        });
        Object.defineProperty(obj, 'address', {
            value: '牛逼牛逼牛逼牛逼',
            enumerable: false,
            configurable: false//不允许属性被删除 true允许删除且不允许再次修改这个属性的特性
        });
        //2.witable用于允许或静止修改属性 默认值也是false
        Object.defineProperty(obj, 'id', {
            writable: false
        });
        obj.id = 2;
        delete obj.address;
        console.log(obj);
        console.log(Object.keys(obj));//遍历对象的属性名
    </script>
</body>

</html>